<template>
	<view>
		<MyTopNav></MyTopNav>
		<view class="bg-white padding-lr-lg">
			<el-row>
				<el-col :span="4">
					<MySideBar actvitiTag="favorite"></MySideBar>
					<MyRank></MyRank>
				</el-col>
				<el-col :span="16" class="padding-xl">
					<view class="">
						<view class="cu-bar bg-white solid-bottom  text-xl">
							<view class="action">
								<text class="cuIcon-titles text-blue"></text>
								我的收藏 ( {{dataList.length}} 道 )
							</view>
						</view>
						<view class="cu-list menu card-menu margin-top-sm " v-for="(item, index) in dataList"
							@click="getQuestionDetail(index)">
							<view class="cu-item arrow">
								<view class="content padding-tb-sm">
									<view class="text-cut cont_text_cut" style="width: 1200upx">
										<text class="text-cut">
											{{index + 1}}. {{item.stem}}
										</text>
									</view>
					
									<view class="text-sm text-grey">
										{{item.categoryName}} - {{item.subjectName}} - {{item.chapterName}}
									</view>
									<view class="text-sm text-grey">
										{{item.createTime}}
										<view class="cu-tag margin-left round">
											<DictTag :options="choiceCategoryOptions" :value="item.choiceCategory" />
										</view>
									</view>
								</view>
							</view>
						</view>
						<view class="bg-white padding-xl" v-if="dataList.length == 0">
							<u-empty mode="data" text="暂无收藏记录"></u-empty>
						</view>
					</view>
				</el-col>
			</el-row>
		</view>
		<MyFooter></MyFooter>
		<QuestionDetail ref="questionDetailModel" @next="goNextQuestion()" @last="goLastQuestion()"></QuestionDetail>
		
	</view>
</template>

<script>
	import {
		getDictData
	} from "@/api/api.js"
	import {
		qbmsQuestionFavoriteList
	} from "@/api/qbms.js"
	
	export default {
		data() {
			return {
				qbankId: 0, // 题库ID
				dataList: [], // 数据列表
				
				choiceCategoryOptions: [],
				curIndex: 0,
			}
		},
		onLoad() {
			this.qbankId = uni.getStorageSync("qbankId");
			this.initDict();
		},
		onShow() {
			
			this.getFavoriteList();
		},
		methods: {
			getFavoriteList() {
				qbmsQuestionFavoriteList({
					categoryId: this.qbankId
				}).then(res => {
					this.dataList = res.data;
				})
			},
		
			/** 获取题目详情 */
			getQuestionDetail(curIndex) {
				this.curIndex = curIndex;
				let questionId = this.dataList[curIndex].questionId;
				this.$refs.questionDetailModel.show(questionId);
			},
			
			/** 初始化字典 */
			initDict() {
				// 获取题库类型字典
				getDictData({
					dictType: "qbms_choice_category"
				}).then(res => {
					this.choiceCategoryOptions = res.data;
				})
			
			},
			
			/** 跳转下一题 */
			goNextQuestion() {
				let nextIndex = this.curIndex + 1;
				// 判断是否到最后一题
				if (this.dataList.length  > nextIndex) {
					this.curIndex = nextIndex;
					this.getQuestionDetail(nextIndex);
				} else {
					uni.showToast({
						title: "没有下一题",
						icon: "none"
					})
				}
			},
			
			/** 跳转上一题 */
			goLastQuestion() {
				let lastIndex = this.curIndex - 1;
				if (lastIndex  >= 0) {
					this.curIndex = lastIndex;
					this.getQuestionDetail(lastIndex);
				} else {
					uni.showToast({
						title: "没有上一题",
						icon: "none"
					})
				}
			},
		}
	}
</script>

<style>

</style>
